package com.ruoyi.common.rabbitmq.consumer;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.ruoyi.common.im.entity.YytImMessage;
import com.ruoyi.common.im.service.YytImMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 监听用户发送消息
 */
@Component
@Slf4j
public class ReadMessageService {

    @Autowired
    private YytImMessageService yytImMessageService;

    @RabbitListener(queues = "yuanju.message.queue")
    public void messageMessage(String message){
        log.info("监听到消息：{}", message);
        List<String> list = Arrays.asList(message.split("\\|"));
        UpdateWrapper<YytImMessage> wrapper = new UpdateWrapper<>();
        wrapper.eq("from_id", list.get(0)).eq("to_id", list.get(1)).set("status", 1).set("reading_time", new Date().getTime());
        yytImMessageService.update(wrapper);
    }
}
